function styleInputs() {
	// Styling checkables.
	$('.checkable').prettyCheckable({
		color: "blue",
		customClass: "checkable"
	});
	
	// Adding tabindexes to styled checkables (newyly created <a> links).
	$('.checkable').each(function(index) {
		var tabindexValue = $(this).attr("tabindex");
		$(this).parent().children("a").attr("tabindex", tabindexValue);
	})
	
	// Styling scrollbars.
	$(".scrollable").nanoScroller({ contentClass: "scrollable-content", alwaysVisible: true });
}


function addRoomSelectionEvents() {
	// Controlling the visibility of room selection controls according to which
	// room selection type is chosen.
	function showAppropriateControls(roomType, pageJustLoaded) {
		if (roomType == "new-room") {
			$('#room-name').prop("readonly", false);
			
			if (pageJustLoaded) {
				$("#existing-rooms").hide();
			}
			else {
				$('#room-name').val("");
				$("#existing-rooms").fadeOut(50);
			}
		}
		if (roomType == "existing-room") {
			$('#room-name').prop("readonly", true);
			
			if (pageJustLoaded) {
				$("#existing-rooms").show();
			}
			else {
				$('#room-name').val("");
				$("#existing-rooms").fadeIn(50);
			}
		}
	}
	
	showAppropriateControls($(".room-type-choice:checked").val(), true);
	
	// Changing room selection type.
	$('.room-type-choice').change(function() {
		showAppropriateControls($(".room-type-choice:checked").val(), false);		
	});
	
	// Selecting a room from the list.
	$(".room-button").click(function (){
		$("#room-name").val($(this).val());
	})
}


function disableMultipleFormSubmission() {
    // Prevents the form from being submitted multiple times.
    $("#login form").submit(function() {
        $(this).unbind("submit").submit(function() {
            return false;
        });
        
        $("#submit").val("Wait...");
    }) 
}


$(document).ready(function() {
	styleInputs();
	addRoomSelectionEvents();
	disableMultipleFormSubmission();
});